package com.kejiguan.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.kejiguan.ui.ExhibitinRunDataPreviewColumnChartActivity;
import com.kejiguan.ui.R;
import com.kejiguan.ui.model.ExhibitionRunItem;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by apple on 16/4/29.
 */
public class NeItemRunDataItemAdapter extends RecyclerView.Adapter<NeItemRunDataItemVH> implements View.OnClickListener{

    private Context mContext;
    private List<ExhibitionRunItem> neItemRunItems;
    private LayoutInflater mInflater;

    public NeItemRunDataItemAdapter(Context context,List<ExhibitionRunItem> neItemRunItems)
    {
        this.mContext=context;
        this.neItemRunItems=neItemRunItems;
        mInflater= LayoutInflater.from(mContext);
    }

    @Override
    public NeItemRunDataItemVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=mInflater.inflate(R.layout.fragment_neitem_rundata_right_item_layout,null);
        return new NeItemRunDataItemVH(itemView);
    }

    @Override
    public void onBindViewHolder(NeItemRunDataItemVH holder, int position) {

        ExhibitionRunItem neItemRunItem=neItemRunItems.get(position);
        holder.neItemId.setText(neItemRunItem.getDisplayName());
        holder.neItemVoltage.setText(String.valueOf(neItemRunItem.getVoltage()==0?"/":neItemRunItem.getVoltage()));
        holder.neItemTemperature.setText(String.valueOf(neItemRunItem.getTemperature()==0?"/":neItemRunItem.getTemperature()));

        holder.clickCount.setText(String.valueOf(neItemRunItem.getClickcount()==0?"/":neItemRunItem.getClickcount()));
        holder.knobcount.setText(String.valueOf(neItemRunItem.getKnobcount()==0?"/":neItemRunItem.getKnobcount()));
        holder.handcount.setText(String.valueOf(neItemRunItem.getHandlecount()==0?"/":neItemRunItem.getHandlecount()));
        holder.orgcount.setText(String.valueOf(neItemRunItem.getMachineOperatedCount()==0?"/":neItemRunItem.getMachineOperatedCount()));
        holder.current.setText(String.valueOf(neItemRunItem.getCurrent()==0?"/":neItemRunItem.getCurrent()));


        holder.neItemVoltage.setOnClickListener(this);
        holder.neItemTemperature.setOnClickListener(this);
        holder.clickCount.setOnClickListener(this);
        holder.knobcount.setOnClickListener(this);
        holder.handcount.setOnClickListener(this);
        holder.orgcount.setOnClickListener(this);
        holder.current.setOnClickListener(this);

    }

    @Override
    public int getItemCount() {


        if (null==neItemRunItems)
        {
            return 0;
        }else {
            return neItemRunItems.size();
        }
    }


    public void setNeItemRunItems(List<ExhibitionRunItem> neItemRunItems) {
        this.neItemRunItems = neItemRunItems;
        notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {

        Intent intent=new Intent(mContext, ExhibitinRunDataPreviewColumnChartActivity.class);
        intent.putExtra("exhibitionRunItems",(Serializable)neItemRunItems);
        switch (v.getId())
        {
            case R.id.voltage:
                intent.putExtra("type",1);
                break;
            case R.id.temperature:
                intent.putExtra("type",2);
                break;
            case R.id.clickcount:
                intent.putExtra("type",3);
                break;
            case R.id.knobcount:
                intent.putExtra("type",4);
                break;
            case R.id.handcount:
                intent.putExtra("type",5);
                break;
            case R.id.orgcount:
                intent.putExtra("type",6);
                break;
            case R.id.current:
                intent.putExtra("type",7);
                break;

        }

        mContext.startActivity(intent);

    }
}
